package denisLunchy;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;


public class AddCLient extends Shell {
	private Text textName;
	private Text textSrName;
	static MVC mvc;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			Display display = Display.getDefault();
			AddCLient shell = new AddCLient(display,mvc);
			shell.open();
			shell.layout();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the shell.
	 * @param display
	 */
	public AddCLient(final Display display,final MVC mvc) {
		super(display, SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.TITLE);
		this.mvc=mvc;
		textName = new Text(this, SWT.BORDER);
		textName.setBounds(27, 37, 76, 21);
		
		textSrName = new Text(this, SWT.BORDER);
		textSrName.setBounds(27, 85, 76, 21);
		
		Button btnNewButton = new Button(this, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				Client client=new Client();
				client.setNameClient(textName.getText());
				client.setSurName(textSrName.getText());
				mvc.getModel().getMenu().arrayClient.add(client);
				mvc.clientInView();
			dispose();
			}
		});
		btnNewButton.setBounds(116, 53, 75, 25);
		btnNewButton.setText("Add");
		
		Label lblName = new Label(this, SWT.NONE);
		lblName.setBounds(32, 10, 55, 15);
		lblName.setText("Name");
		
		Label lblSurname = new Label(this, SWT.NONE);
		lblSurname.setBounds(32, 64, 55, 15);
		lblSurname.setText("SurName");
		createContents();
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("Add Client");
		setSize(222, 166);

	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

}
